setwd("C:/Users/Dan/Dropbox/Projects/SA_cohort_effects")
library(foreign)
library(ebal)
library(Matching)
library(xtable)
library(ggplot2)
library(rdd)

compl = seq(0.15,1,0.01)
te = c()
for(i in 1:length(compl)){
  te[i] = 2.964/compl[i]
}
    
ci.up = c()
for(i in 1:length(compl)){
  ci.up[i] = 5.010728/compl[i]
}

ci.lo = c()
for(i in 1:length(compl)){
  ci.lo[i] = .9174961/compl[i]
}

plot.me = data.frame(cbind(compl,te,ci.up,ci.lo))
colnames(plot.me) = c("compl","te","ci_up","ci_lo")

pdf(file="LATEs.pdf", height=6,width=8)
ggplot(plot.me, aes(x=compl, y=te)) + 
  geom_line(data=plot.me, aes(compl, te), color="blue", lwd=1.5) + 
  geom_line(data=plot.me, aes(compl, ci_up), color="dark grey", lwd=1,lty=2) + 
  geom_line(data=plot.me, aes(compl, ci_lo), color="dark grey", lwd=1,lty=2) + 
  scale_y_continuous(limits=c(-2,20), "LATE (Percentage Points)")  +
  scale_x_continuous("Compliance ratio for the treated") + 
  geom_vline(aes(xintercept=0.86), color="black") +
  geom_text(mapping=aes(0.88,18,label = text2), data=data.frame(x2=0.88, y2=18, text2=paste("National Turnout 1994 (86%)"), parse=TRUE, size=5)) + 
  geom_text(mapping=aes(0.88,16,label = text2), data=data.frame(x2=0.88, y2=16, text2=paste("ATT = 3.44pp"), parse=TRUE, size=5)) + 
  geom_vline(aes(xintercept=0.35), color="black") +
  geom_text(mapping=aes(0.37,18,label = text2), data=data.frame(x2=0.37, y2=18, text2=paste("Turnout 18yr 2009 (35%)"), parse=TRUE, size=5)) + 
  geom_text(mapping=aes(0.37,16,label = text2), data=data.frame(x2=0.37, y2=16, text2=paste("ATT = 8.46pp"), parse=TRUE, size=5)) + 
    theme_bw() +
  theme(axis.line = element_line(colour = "black"),
        panel.border = element_blank(),
        panel.background = element_blank(),
        axis.title.x=element_text(size=12),
        axis.title.y=element_text(size=12,angle=90))
dev.off()  

